{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card">
    <div class="layui-card-body">
        <blockquote class="layui-elem-quote">
            发布商品时，不同类型显示不同的价格
        </blockquote>
        <form class="layui-form" action="">
            <div class="layui-form-item" style="width: 500px;">
                <table class="layui-table">
                    <tr>
                        <th>类型</th>
                        <th>名称</th>
                        <th>字段名</th>
                    </tr>
                    {foreach $config as $val}
                        <tr>
                            <td>
                                {foreach $leixing as $id=>$name}
                                <input type="checkbox" value="{$id}" name="leixing[{$val['field']}][]"  {if in_array($id,$val['leixing'])}checked='checked'{/if} title="{$name}" /> <br/>
                                {/foreach}
                            </td>
                            <td><input type="text" class="layui-input" name="name[{$val['field']}]" value="{$val.name}"></td>
                            <td>{$val.field}<input type="hidden" size="15" name="field[{$val['field']}]" value="{$val.field}"></td>
                        </tr>
                    {/foreach}
                    {for start='1' end='40' name='i'}
                        <tr>
                            <td>
                                {foreach $leixing as $id=>$name}
                                    <input  type="checkbox" value="{$id}" name="leixing[{$i}][]"  {if $id=="5"}checked='checked'{/if} /> {$name}<br />
                                {/foreach}
                            </td>
                            <td><input class="layui-input" type="text" size="15" name="name[{$i}]" value=""></td>
                            <td><input class="layui-input" type="text" size="15" name="field[{$i}]" value=""></td>
                        </tr>
                    {/for}
                </table>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });
        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('goodsprice')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('操作成功');
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });


    });
</script>
</body>
</html>